<?php
/**
 * 附件模型
 * BaseAttachmentModel.php
 * ==============================================
 * 版权所有 2013-2014
 * ----------------------------------------------
 * 这不是一个自由软件，未经授权不许任何使用和传播。
 * ----------------------------------------------
 * 
 * @package xcs
 * @author huangdaohai <huangdaohai.2007@163.com>
 * @version V1.0
 * @access public
 */
class BaseAttachmentModel extends CActiveRecord
{
	/**
	 * Returns the static model of the specified AR class.
	 * @param string $className active record class name.
	 * @return Attachment the static model class
	 */
	public static function model($className=__CLASS__)
	{
		return parent::model($className);
	}

	/**
	 * @return string the associated database table name
	 */
	public function tableName()
	{
		return '{{base_attachment}}';
	}

	/**
	 * @return array validation rules for model attributes.
	 */
	public function rules()
	{
		// NOTE: you should only define rules for those attributes that
		// will receive user inputs.
		return array(
			array('uid, postip, filename, size, type, extensionname, filepath,serverpath, dateline,location', 'required'),
			array('uid, size, width, height, isuse, dateline', 'numerical', 'integerOnly'=>true),
			array('location', 'length', 'max'=>10),
			array('postip', 'length', 'max'=>20),
			array('filename', 'length', 'max'=>150),
			array('type, modtype', 'length', 'max'=>50),
			array('extensionname', 'length', 'max'=>10),
			array('filepath,serverpath', 'length', 'max'=>255),
			// The following rule is used by search().
			// Please remove those attributes that should not be searched.
			array('aid, uid, postip, filename, size, type, extensionname, filepath,serverpath, width, height, modtype, isuse, dateline', 'safe', 'on'=>'search'),
		);
	}

	/**
	 * @return array relational rules.
	 */
	public function relations()
	{
		// NOTE: you may need to adjust the relation name and the related
		// class name for the relations automatically generated below.
		return array(
		);
	}

	/**
	 * @return array customized attribute labels (name=>label)
	 */
	public function attributeLabels()
	{
		return array(
			'aid' => 'ID',
			'uid' => '上传者',
			'postip' => '上传者IP',
			'filename' => '附件名称',
			'size' => '附件大小',
			'type' => '附件类型',
			'extensionname' => '扩展名称',
			'filepath' => '访问路径',
			'serverpath' => '上传路径',
			'width' => '宽度',
			'height' => '高度',
			'modtype' => '上传类型',
			'isuse' => '是否使用',
			'dateline' => '上传时间',
			'location' => 'location'
		);
	}

	/**
	 * Retrieves a list of models based on the current search/filter conditions.
	 * @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions.
	 */
	public function search()
	{
		// Warning: Please modify the following code to remove attributes that
		// should not be searched.

		$criteria=new CDbCriteria;

		$criteria->compare('aid',$this->aid);
		$criteria->compare('uid',$this->uid);
		$criteria->compare('postip',$this->postip,true);
		$criteria->compare('filename',$this->filename,true);
		$criteria->compare('size',$this->size);
		$criteria->compare('type',$this->type,true);
		$criteria->compare('extensionname',$this->extensionname,true);
		$criteria->compare('filepath',$this->filepath,true);
		$criteria->compare('serverpath',$this->serverpath,true);
		$criteria->compare('width',$this->width);
		$criteria->compare('height',$this->height);
		$criteria->compare('modtype',$this->modtype,true);
		$criteria->compare('isuse',$this->isuse);
		$criteria->compare('dateline',$this->dateline);

		return new CActiveDataProvider($this, array(
			'criteria'=>$criteria,
		));
	}
}